﻿using Apps.Common;
using Apps.Models;
using Apps.Models.S;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Apps.BLL.S
{
    public partial class S_BLENDSAMPLEBLL
    {
        public DBContainer db = new DBContainer();
        /// <summary>
        /// 
        /// </summary>
        /// <param name="batch"></param>
        /// <param name="startdate1">开始时间起</param>
        /// <param name="startdate2">开始时间止</param>
        /// <param name="enddate1">结束时间起</param>
        /// <param name="enddate2">结束时间止</param>
        /// <returns></returns>
        public List<V_S_BLENDSAMPLE_RC> GetList_RC(ref GridPager pager, string batch, string startdate1,  string startdate2, string enddate1,string enddate2)
        {
            IQueryable<V_S_BLENDSAMPLE_RC> queryData = this.db.V_S_BLENDSAMPLE_RC.AsQueryable();
            if (!string.IsNullOrEmpty(batch))
            {
                queryData = queryData.Where(m => m.BATCH_CODE.Contains(batch));
            }
            if (!string.IsNullOrEmpty(startdate1))
            {
                DateTime dStartDate1 = DateTime.ParseExact(startdate1, "yyyy-MM-dd", null);
                queryData = queryData.Where(m => m.BEGIN_TIME >= dStartDate1);
            }
            if (!string.IsNullOrEmpty(startdate2))
            {
                DateTime dStartDate2 = DateTime.ParseExact(startdate2, "yyyy-MM-dd", null).AddDays(1);
                queryData = queryData.Where(m => m.BEGIN_TIME < dStartDate2);
            }
            if (!string.IsNullOrEmpty(enddate1))
            {
                DateTime dEndDate1 = DateTime.ParseExact(enddate1, "yyyy-MM-dd", null);
                queryData = queryData.Where(m => m.END_TIME >= dEndDate1);
            }
            if (!string.IsNullOrEmpty(enddate2))
            {
                DateTime dEndDate2 = DateTime.ParseExact(enddate2, "yyyy-MM-dd", null).AddDays(1);
                queryData = queryData.Where(m => m.END_TIME < dEndDate2);
            }

            pager.totalRows = queryData.Count();

            //排序
            queryData = LinqHelper.SortingAndPaging(queryData, pager.sort, pager.order, pager.page, pager.rows);
            //return TransHelper.TransExpList<V_S_BLENDSAMPLE,V_S_BLENDSAMPLEModel>(queryData.ToList());
            return queryData.ToList();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="batch"></param>
        /// <param name="startdate1">开始时间起</param>
        /// <param name="startdate2">开始时间止</param>
        /// <param name="enddate1">结束时间起</param>
        /// <param name="enddate2">结束时间止</param>
        /// <returns></returns>
        public List<V_S_BLENDSAMPLE_RL> GetList_RL(ref GridPager pager, string batch, string startdate1, string startdate2, string enddate1, string enddate2)
        {
            IQueryable<V_S_BLENDSAMPLE_RL> queryData = this.db.V_S_BLENDSAMPLE_RL.AsQueryable();
            if (!string.IsNullOrEmpty(batch))
            {
                queryData = queryData.Where(m => m.BATCH_CODE.Contains(batch));
            }
            if (!string.IsNullOrEmpty(startdate1))
            {
                DateTime dStartDate1 = DateTime.ParseExact(startdate1, "yyyy-MM-dd", null);
                queryData = queryData.Where(m => m.BEGIN_TIME >= dStartDate1);
            }
            if (!string.IsNullOrEmpty(startdate2))
            {
                DateTime dStartDate2 = DateTime.ParseExact(startdate2, "yyyy-MM-dd", null).AddDays(1);
                queryData = queryData.Where(m => m.BEGIN_TIME < dStartDate2);
            }
            if (!string.IsNullOrEmpty(enddate1))
            {
                DateTime dEndDate1 = DateTime.ParseExact(enddate1, "yyyy-MM-dd", null);
                queryData = queryData.Where(m => m.END_TIME >= dEndDate1);
            }
            if (!string.IsNullOrEmpty(enddate2))
            {
                DateTime dEndDate2 = DateTime.ParseExact(enddate2, "yyyy-MM-dd", null).AddDays(1);
                queryData = queryData.Where(m => m.END_TIME < dEndDate2);
            }

            pager.totalRows = queryData.Count();

            //排序
            queryData = LinqHelper.SortingAndPaging(queryData, pager.sort, pager.order, pager.page, pager.rows);
            //return TransHelper.TransExpList<V_S_BLENDSAMPLE,V_S_BLENDSAMPLEModel>(queryData.ToList());
            return queryData.ToList();
        }
    }
}
